#include <time.h>
#include <assert.h>

#include <vector>
#include <fstream>

#include "../../include/GlobalMemory.hpp"

extern void scan_on_gpu(CH::GlobalMemory<int>& i_d, const int& block_dim);

int main(int argc, char* argv[])
{
	srand( time(0) );
	
	//int block_dim = 128; ///block dimension
	int block_dim = 256; ///block dimension

	int data_dim =  block_dim * 2;
	int vector_len = 12345; ///# of numbers to sum

	for(int c = 0; c < 100; c++)
	{
		///host data initialization
		std::vector<int> in_h( vector_len ); 
		for(int i = 0; i < in_h.size(); i++)
			in_h[i] = rand() % 20;

		///exclusive scan on cpu
		std::vector<int> cpu_scan(vector_len); 
		cpu_scan[0] = 0;
		for(int i = 1; i < cpu_scan.size(); i++)
			cpu_scan[i] = cpu_scan[i - 1] + in_h[i - 1];

		///send data to gpu
		CH::GlobalMemory<int> in_d = in_h;

		///exclusive scan on gpu
		scan_on_gpu( in_d, block_dim );

		///get result back to host
		std::vector<int> gpu_scan;
		in_d.get_gpu_data( gpu_scan );
		
		assert( gpu_scan == cpu_scan );
	}


	return 0;
}